﻿using System;

namespace ChessKit.Common
{
  public static class Disposable
  {
    private class DisposableImpl : IDisposable
    {
      private readonly Action _dispose;

      public DisposableImpl(Action dispose)
      {
        _dispose = dispose;
      }

      public void Dispose()
      {
        _dispose();
      }
    }
    private class NullDisposableImpl : IDisposable
    {
      public void Dispose()
      {
      }
    }
    public static IDisposable Create(Action dispose = null)
    {
      return dispose == null ? new NullDisposableImpl()
        : (IDisposable) new DisposableImpl(dispose);
    }
  }
}
